brute force implementation *1100

Please click on ads to support us..

Python Code:

import math
num,k = list(map(int, input().split(' ')))
count = 0
for i in (range(num)):
         rang = list(map(int, input().split(' ')))
         count += rang[1]-rang[0]+1

count = k* math.ceil(count/k) - count
print(count)

C++ Code:

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include<cmath> //float result = pow(b,p)  //trunc(10.25)=10       // floor(10.55)=10  // ceil(10.55)=11  //round(10.1)=10 , round(10.55)=11
#include <unordered_map> // unordered_map<int,int>mp;
using namespace std;

#define fast                    \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);

// -842150451
// a=97 , z= 122 , A=65 ,Z=90

#include<set>
int main() {
	//extern  int arr [5]  ;
	//fast	
	int before=0 , after =0 ;
	int n, k; cin >> n >> k;

	for (int i = 0;i<n;i++) {
		int l; cin >> l;
		int r; cin >> r;    
		before += 1 + r - l;
	}
	
	for (int i = 0; true; i++) {

		if ((after+before) % k == 0) {
			break;
		}
			after++;
		
	}

		cout << after << endl;
		
}


Comments

Submit
0 Comments
More Questions

600C - Make Palindrome
1669D - Colorful Stamp
1669B - Triple
1669A - Division
1669H - Maximal AND
1669E - 2-Letter Strings
483A - Counterexample
3C - Tic-tac-toe
1669F - Eating Candies
1323B - Count Subrectangles
991C - Candies
1463A - Dungeon
1671D - Insert a Progression
1671A - String Building
1671B - Consecutive Points Segment
1671C - Dolce Vita
1669G - Fall Down
4D - Mysterious Present
1316B - String Modification
1204A - BowWow and the Timetable
508B - Anton and currency you all know
1672A - Log Chopping
300A - Array
48D - Permutations
677C - Vanya and Label
1583B - Omkar and Heavenly Tree
1703C - Cypher
1511C - Yet Another Card Deck
1698A - XOR Mixup
1702E - Split Into Two Sets